<?php

!defined('IN_APP') && exit('Access Denied');

class admin_settingcontrol extends controlbase {


    function ondefault() {
        $this->onbase();
    }

    /* 基本设置 */

    function onbase() {
        $tpllist = $this('setting')->tpl_list();
        if (isset($this->post['submit'])) {
            $setting['site_name'] = $this->post['site_name'];
            $setting['site_icp'] = $this->post['site_icp'];
            $setting['tpl_dir'] = $this->post['tpl_dir'];
            $setting['site_statcode'] = $this->post['site_statcode'];
            $setting['index_life'] = $this->post['index_life'];
            $this('setting')->update($setting);
            $message = '站点设置更新成功！';
        }else{
        	$setting=$this->setting;
        }
        include template('setting_base');
    }

    /* 时间设置 */

    function ontime() {
        $timeoffset = array(
            '-12' => '(标准时-12:00) 日界线西',
            '-11' => '(标准时-11:00) 中途岛、萨摩亚群岛',
            '-10' => '(标准时-10:00) 夏威夷',
            '-9' => '(标准时-9:00) 阿拉斯加',
            '-8' => '(标准时-8:00) 太平洋时间(美国和加拿大)',
            '-7' => '(标准时-7:00) 山地时间(美国和加拿大)',
            '-6' => '(标准时-6:00) 中部时间(美国和加拿大)、墨西哥城',
            '-5' => '(标准时-5:00) 东部时间(美国和加拿大)、波哥大',
            '-4' => '(标准时-4:00) 大西洋时间(加拿大)、加拉加斯',
            '-3.5' => '(标准时-3:30) 纽芬兰',
            '-3' => '(标准时-3:00) 巴西、布宜诺斯艾利斯、乔治敦',
            '-2' => '(标准时-2:00) 中大西洋',
            '-1' => '(标准时-1:00) 亚速尔群岛、佛得角群岛',
            '0' => '(格林尼治标准时) 西欧时间、伦敦、卡萨布兰卡',
            '1' => '(标准时+1:00) 中欧时间、安哥拉、利比亚',
            '2' => '(标准时+2:00) 东欧时间、开罗，雅典',
            '3' => '(标准时+3:00) 巴格达、科威特、莫斯科',
            '3.5' => '(标准时+3:30) 德黑兰',
            '4' => '(标准时+4:00) 阿布扎比、马斯喀特、巴库',
            '4.5' => '(标准时+4:30) 喀布尔',
            '5' => '(标准时+5:00) 叶卡捷琳堡、伊斯兰堡、卡拉奇',
            '5.5' => '(标准时+5:30) 孟买、加尔各答、新德里',
            '6' => '(标准时+6:00) 阿拉木图、 达卡、新亚伯利亚',
            '7' => '(标准时+7:00) 曼谷、河内、雅加达',
            '8' => '(标准时+8:00)北京、重庆、香港、新加坡',
            '9' => '(标准时+9:00) 东京、汉城、大阪、雅库茨克',
            '9.5' => '(标准时+9:30) 阿德莱德、达尔文',
            '10' => '(标准时+10:00) 悉尼、关岛',
            '11' => '(标准时+11:00) 马加丹、索罗门群岛',
            '12' => '(标准时+12:00) 奥克兰、惠灵顿、堪察加半岛');
        if (isset($this->post['submit'])) {
            $setting['time_offset'] = $this->post['time_offset'];
            $setting['time_diff'] = $this->post['time_diff'];
            $setting['date_format'] = $this->post['date_format'];
            $setting['time_format'] = $this->post['time_format'];
            $setting['time_friendly'] = $this->post['time_friendly'];
            $this('setting')->update($setting);
            $message = '时间设置更新成功！';
        }else{
        	$setting=$this->setting;
        }
        include template('setting_time');
    }


    /* 注册设置 */

    function onregister() {
        if (isset($this->post['submit'])) {
            $setting['allow_register'] = $this->post['allow_register'];
            $setting['access_email'] = $this->post['access_email'];
            $setting['censor_email'] = $this->post['censor_email'];
            $setting['censor_username'] = $this->post['censor_username'];
            $this('setting')->update($setting);
            $message = '注册设置更新成功！';
        }else{
        	$setting=$this->setting;
        }
        include template('setting_register');
    }

    /* 邮件设置 */

    function onmail() {
        if (isset($this->post['submit'])) {
            foreach ($this->post as $key => $value) {
                if ('mail' == substr($key, 0, 4)) {
                    $setting[$key] = $value;
                }
            }
            $this('setting')->update($setting);
            $message = '邮件设置更新成功！';
        }else{
        	$setting=$this->setting;
        }
        include template('setting_mail');
    }

    

    /* 缓存设置 */

    function oncache() {
        $tplchecked = $datachecked = false;
        if (isset($this->post['submit'])) {
            if (isset($this->post['type'])) {
                if (in_array('tpl', $this->post['type'])) {
                    $tplchecked = true;
                    cleardir(APP_ROOT . '/data/view');
                }
                if (in_array('data', $this->post['type'])) {
                    $datachecked = true;
                    cleardir(APP_ROOT . '/data/cache');
                }
                $message = '缓存更新成功！';
            } else {
                $tplchecked = $datachecked = false;
                $message = '没有选择缓存类型！';
                $type = 'errormsg';
            }
        }
        include template('setting_cache');
    }



    /* SEO设置 */

    function onseo() {
        if (isset($this->post['submit'])) {
            foreach ($this->post as $key => $value) {
                if ('seo' == substr($key, 0, 3)) {
                    $setting[$key] = $value;
                }
            }
            $this('setting')->update($setting);
            $message = 'SEO设置更新成功！';
        }else{
        	$setting=$this->setting;
        }
        include template('setting_seo');
    }

 

}
